Repository navigation
Conversation
olszomal
left a comment
There was a problem hiding this comment.
According to [MS-CFB], section 2.1, valid sector numbers range from 0 to MAXREGSECT (0xFFFFFFFA), inclusive.
The proposed condition still rejects sector 0, which is valid, and accepts reserved values such as DIFSECT and FATSECT, which cannot be used as links to the next sector.
I suggest replacing the entire condition with:
if (nextSectorLocation > MAXREGSECT) {This also fixes the pre-existing rejection of sector 0.
The same validation should be applied consistently in:
get_next_sector()get_next_mini_sector()get_fat_sector_location()sector_offset_to_address()mini_sector_offset_to_address()
The last two functions currently use >= MAXREGSECT, incorrectly excluding the maximum valid sector number.
The new FAT sector count check and the change to read_mini_stream() look correct.
olszomal
left a comment
There was a problem hiding this comment.
All my previous comments have been addressed. Sector number validation is now consistent with MS-CFB across all five functions.
I also appreciate the new regression test covering backward links to sector 0 in both FAT and MiniFAT chains and checking stream preservation.
Looks good to me.
Reject reserved sector markers when a chain requires another sector, and bound FAT lookups by the header's declared sector count. This avoids excessive CPU use on malformed MSI files while allowing valid links to sector zero. Stop reading a mini stream once its requested bytes have been copied so a valid end-of-chain marker is not mistaken for an error. Test that signing and removing signatures preserve stream data when FAT and MiniFAT chains link back to sector zero.
c8bb25a to
c67e337
Compare
Pull Request Type
Related Issue
Issue number: N/A
Current Behavior
Malformed MSI sector chains can treat
ENDOFCHAINas a sector number, causing millions of unnecessary DIFAT-walk iterations during signing or verification.New Behavior
Reject chain terminators and FAT sector numbers outside the header's declared range before walking the chain. Stop reading a mini stream once its requested bytes have been copied, avoiding an unnecessary lookup past its final sector.
Scope of Changes
MSI sector-chain validation and its release note.
Testing
Release build succeeded with GCC 16.2 and OpenSSL 3.6.5. All 29 selected CTest checks passed: the MSI storage-tree tests and HTTP-server setup/cleanup (
ctest -R '^(start_server|stop_server|msi_tree_.*)$' --output-on-failure).License Declaration